#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date    : 2016-04-21 16:12:28
# @Author  : Gtlions Lai (gtlions.l@qq.com)
# @Link    : http://blog.csdn.net/gtlions
# @Version : 1.0.0
"""summarization ahout this script.

detail ahout this script

    Class(): summarization about Class
    ...
    function(): summarization about function
    ...
"""

from flask import Flask, render_template, redirect, request
from flask.ext.sqlalchemy import SQLAlchemy
import os

app = Flask(__name__)
basedir = os.path.abspath(os.path.dirname(__file__))
app.config['SQLALCHEMY_DATABASE_URI'] = "sqlite:///" + os.path.join(basedir, 'note.db')
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
db = SQLAlchemy(app)

class Note(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(80))
    body = db.Column(db.Text)

    def __init__(self, title, body):
        self.title = title
        self.body = body

@app.route("/")
def home():
    return render_template("home.html")


@app.route("/notes/create", methods=["GET", "POST"])
def create_note():
    if request.method == "GET":
        return render_template("create_note.html")
    else:
        title = request.form["title"]
        body = request.form["body"]
        note = Note(title=title, body=body)
        db.session.add(note)
        db.session.commit()

        return redirect("/notes/create", code=302, Response=None)


@app.route("/notes")
def notes():
    return "view notes"


if __name__ == "__main__":
    app.run(debug=True)
# app.run(Debug=True)